package cn.cycleif.admin.controller;

import cn.cycleif.admin.service.AdminUserService;
import cn.cycleif.util.R;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date: 25/1/23-11:45
 * @Desc:
 */

@RestController
@RequestMapping("/sys/user")
@Tag(name = "用户管理", description = "禁用，授权等")
@SaCheckRole("admin")
public class AdminUserController {

  @Autowired
  private AdminUserService adminUserService;

  @GetMapping("/logout/{id}")
  @Operation(summary = "强制账号下线")
  public R<String> logout(@PathVariable("id") Integer id) {
    StpUtil.logout(id);
    return R.success();
  }

  @PutMapping("/disable/{id}")
  @Operation(summary = "禁用账号")
  public R<String> disable(@PathVariable("id") Integer id) {
    return adminUserService.disable(id);
  }

  @PutMapping("/status/{id}")
  @Operation(summary = "更改账号状态")
  public R<String> status(@PathVariable("id") Integer id, @RequestParam Integer status) {
    return adminUserService.status(id, status);
  }

  @GetMapping("/list")
  @Operation(summary = "获取账号列表")
  public R<Object> list(
      @RequestParam("status") @Nullable Integer status
  ) {
    return adminUserService.selectPage(status);
  }


}
